using System.Collections.Generic;
using System.Diagnostics;

namespace MinecraftGPS.Data
{
    [DebuggerDisplay("{Name} - {Value}")]
    class Tag
    {
        private readonly bool isEndTag;
        private readonly string name;
        private readonly object value;
        private readonly Dictionary<string, Tag> children;

        public Tag()
            : this("", null, new Tag[0])
        {
            this.isEndTag = true;
        }

        public Tag(object value)
            : this("", value, new Tag[0])
        {
        }

        public Tag(string name, object value)
            : this(name, value, new Tag[0])
        {
        }

        public Tag(string name, object value, IEnumerable<Tag> children)
        {
            this.isEndTag = false;
            this.name = name;
            this.value = value;

            this.children = new Dictionary<string, Tag>();
            foreach (var child in children)
                this.children.Add(child.Name, child);
        }

        public Tag Child(string name)
        {
            return children[name];
        }

        public bool IsEndTag { [DebuggerStepThrough] get { return isEndTag; } }

        public string Name { [DebuggerStepThrough] get { return name; } }

        public object Value { [DebuggerStepThrough] get { return value; } }

        public IEnumerable<Tag> Children { [DebuggerStepThrough] get { return this.children.Values; } }
    }
}